package graduate.cslg.com.universityshopping.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import graduate.cslg.com.universityshopping.R;
import graduate.cslg.com.universityshopping.entity.ScoreInfoBean;

public class ScoreInfoAdapter extends RecyclerView.Adapter<ScoreInfoAdapter.ViewHolder> {

    private Context mContext;
    private List<ScoreInfoBean> mScoreInfoBeans;

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView scorePlace;
        TextView scoreReason;
        TextView scoreCount;

        public ViewHolder(View itemView) {
            super(itemView);
            scorePlace = itemView.findViewById(R.id.count_place);
            scoreReason = itemView.findViewById(R.id.count_reason);
            scoreCount = itemView.findViewById(R.id.count_score);
        }
    }

    public ScoreInfoAdapter(List<ScoreInfoBean> scoreInfoBeans) {
        mScoreInfoBeans = scoreInfoBeans;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_score_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ScoreInfoBean scoreInfoBean = mScoreInfoBeans.get(position);
        holder.scoreCount.setText(String.valueOf(scoreInfoBean.getScore_count()));
        holder.scoreReason.setText(scoreInfoBean.getScore_reason());
        holder.scorePlace.setText(scoreInfoBean.getScore_place());
    }

    @Override
    public int getItemCount() {
        return mScoreInfoBeans.size();
    }
}
